; sample program 2
; includes a loop and load procedure for variable var
; calculate the sum of 1 to n

	START
	IN 1,R0
	LDN var,R31	; initialize variable var
	LOAD R31,R3	; load variable in register
loop:	ADD R2,R3,R2	; begin loop
	OUT R1,2
	ADD R1,R2,R1
	SUB R0,R2,R4	; break definition for loop
	JMPN end	; jump to the end of loop
	JMP loop	; jump to the begin of loop
end:	HALT		; end loop

var: 	DC 1		; declare variable var

